home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / applications / databases / fbase106.lha / FBase / FBaseSrc.lha / IO.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-13  |  16.5 KB  |  593 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1993 by Amit Fridman
  4.  *
  5.  *    Name .....: IO.c
  6.  *    Created ..: Tuesday 14-Dec-93 11:42:13
  7.  *    Revision .: 5
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    13-May-94   Amit Fridman           v1.05 Preliminary release
  12.  *    15-Apr-94   Amit Fridman           v1.04 Beta version complete
  13.  *    24-Mar-94   Amit Fridman           v1.03 Added Keys
  14.  *    24-Feb-94   Amit Fridman           v1.02
  15.  *    07-Jan-94   Amit Fridman           v1.01
  16.  *    14-Dec-93   Amit Fridman           Created this file!
  17.  *
  18.  * $Revision Header ********************************************************/
  19. #define REVISION    5
  20.  
  21. /* IO operations */
  22.  
  23. #include "FBase.h"
  24. #include "Protos.h"
  25.  
  26. #define ID_FBASE1  MAKE_ID('F','B','S','1')
  27. #define ID_KEYS    MAKE_ID('K','E','Y','S')
  28. #define ID_FLOPPY  MAKE_ID('F','L','P','Y')
  29. #define ID_RECORD  MAKE_ID('R','C','R','D')
  30.  
  31. static BOOL    GetSaveName(void);
  32. static BOOL    GetLoadName(void);
  33. static RECORD *LinkRecord(FLOPPY *, ULONG);
  34. static BOOL    ChunkIs(ULONG, ULONG);
  35. static void    PrintRecord(FILE *fd,RECORD *Record);
  36. static void    PrintRecordFull(FILE *fd,RECORD *Record);
  37.  
  38. extern char        *CY_Labels[];
  39. extern Object      *App;
  40. extern Object      *WI_Main;
  41. extern Object      *LV_Floppies,*LV_Files;
  42. extern Object      *ST_Match;
  43. extern Object      *CM_Keys,*CM_KeyAnd;
  44. extern struct List  FloppyList;
  45. extern FLOPPY      *MainFloppy;
  46. extern RECORD      *MainRecord;
  47. extern BOOL         DataChanged;
  48. extern LONGBITS     CurKeyMask;
  49.  
  50. static struct IFFHandle *Iff;
  51. static UBYTE             SaveName[108];
  52. static UBYTE             LoadName[108];
  53.  
  54.  
  55. void InitDiskNames()
  56. {
  57.    struct DosList *dl;
  58.    char           *ptr,name[32][32];
  59.    int             i,devs,j,sys;
  60.  
  61.    dl=LockDosList(LDF_DEVICES|LDF_READ);
  62.    for (i=0,devs=0; i<32; i++) {
  63.       if (dl=NextDosEntry(dl,LDF_DEVICES)) {
  64.          ptr=BADDR(dl->dol_Name);
  65.          strncpy(name[devs],&ptr[1],ptr[0]);
  66.          name[devs][ptr[0]]=0;
  67.          strcat(name[devs],":");
  68.          devs++;
  69.       } else
  70.          break;
  71.    }
  72.    UnLockDosList(LDF_DEVICES|LDF_READ);
  73.  
  74.    for (j=0,sys=0; j<devs; j++) {
  75.       if (IsFileSystem(name[j])) {
  76.          CY_Labels[sys]=AllocMem(strlen(name[j])+1,MEMF_CLEAR);
  77.          if (!CY_Labels[sys]) break;
  78.          strcpy(CY_Labels[sys],name[j]);
  79.          sys++;
  80.       }
  81.    }
  82.    tqsort(CY_Labels,sys);
  83.    while (sys<32)
  84.       CY_Labels[sys++]=NULL;
  85. }
  86.  
  87. void SetSaveName()
  88. {
  89.    SaveName[0]='\0';
  90.    LoadName[0]='\0';
  91. }
  92.  
  93. void SaveKeys()
  94. {
  95.    STRPTR *Key;
  96.    WORD    KeyNum;
  97.    UBYTE   LocalKey[MAXKEYLEN];
  98.  
  99.    if (!PushChunk(Iff,NULL,ID_KEYS,IFFSIZE_UNKNOWN)) {
  100.       InitKeyScan();
  101.       while (Key=GetNextKey(&KeyNum)) {
  102.          strcpy(LocalKey,*Key);
  103.          WriteChunkBytes(Iff,&KeyNum,sizeof(KeyNum));
  104.          WriteChunkBytes(Iff,LocalKey,MAXKEYLEN);
  105.       }
  106.       PopChunk(Iff);
  107.    }
  108. }
  109.  
  110. void SaveAllFloppies(struct List *FList)
  111. {
  112.    struct Node *Floppy;
  113.  
  114.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  115.    Floppy=FList->lh_Head;
  116.    while (Floppy->ln_Succ) {
  117.       SaveFloppy((FLOPPY *)Floppy);
  118.       Floppy=Floppy->ln_Succ;
  119.    }
  120.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  121. }
  122.  
  123. void SaveFloppy(FLOPPY *Floppy)
  124. {
  125.    struct Node *RList;
  126.  
  127.    if (!PushChunk(Iff,ID_FLOPPY,ID_FORM,IFFSIZE_UNKNOWN)) {
  128.       RList=Floppy->Records.lh_Head;
  129.       while (RList->ln_Succ) {
  130.          SaveRecord((RECORD *)RList);
  131.          RList=RList->ln_Succ;
  132.       }
  133.       PopChunk(Iff);
  134.    }
  135. }
  136.  
  137. void SaveRecord(RECORD *Record)
  138. {
  139.    char  Empty[] = { 0,0,0,0 };
  140.    short len;
  141.  
  142.    if (!PushChunk(Iff,NULL,ID_RECORD,IFFSIZE_UNKNOWN)) {
  143.       WriteChunkBytes(Iff,&Record->Flags,sizeof(Record->Flags));
  144.       WriteChunkBytes(Iff,&Record->Size,sizeof(Record->Size));
  145.       WriteChunkBytes(Iff,&Record->Depth,sizeof(Record->Depth));
  146.       WriteChunkBytes(Iff,&Record->Unique,sizeof(Record->Unique));
  147.       WriteChunkBytes(Iff,&Record->Keys,sizeof(Record->Keys));
  148.       if (Record->Next)
  149.          WriteChunkBytes(Iff,&Record->Next->Unique,sizeof(Record->Unique));
  150.       else
  151.          WriteChunkBytes(Iff,Empty,sizeof(Record->Unique));
  152.       if (Record->Parent)
  153.          WriteChunkBytes(Iff,&Record->Parent->Unique,sizeof(Record->Unique));
  154.       else
  155.          WriteChunkBytes(Iff,Empty,sizeof(Record->Unique));
  156.       if (Record->Sub)
  157.          WriteChunkBytes(Iff,&Record->Sub->Unique,sizeof(Record->Unique));
  158.       else
  159.          WriteChunkBytes(Iff,Empty,sizeof(Record->Unique));
  160.       if (Record->FName) {
  161.          len=strlen(Record->FName)+1;
  162.          WriteChunkBytes(Iff,&len,sizeof(len));
  163.          WriteChunkBytes(Iff,Record->FName,len);
  164.       } else {
  165.          len=0;
  166.          WriteChunkBytes(Iff,&len,sizeof(len));
  167.       }
  168.       if (Record->FRem) {
  169.          len=strlen(Record->FRem)+1;
  170.          WriteChunkBytes(Iff,&len,sizeof(len));
  171.          WriteChunkBytes(Iff,Record->FRem,len);
  172.       } else {
  173.          len=0;
  174.          WriteChunkBytes(Iff,&len,sizeof(len));
  175.       }
  176.       PopChunk(Iff);
  177.    }
  178. }
  179.  
  180. void DoSave()
  181. {
  182.    if (SaveName[0]==0)
  183.       if (!GetSaveName())
  184.          return;
  185.  
  186.    if (Iff=AllocIFF()) {
  187.       if (Iff->iff_Stream=(ULONG)Open(SaveName,MODE_NEWFILE)) {
  188.          InitIFFasDOS(Iff);
  189.          if (!OpenIFF(Iff,IFFF_WRITE)) {
  190.             if (!PushChunk(Iff,ID_FBASE1,ID_FORM,IFFSIZE_UNKNOWN)) {
  191.                SaveKeys();
  192.                SaveAllFloppies(&FloppyList);
  193.                DataChanged=FALSE;
  194.             }
  195.             CloseIFF(Iff);
  196.          }
  197.          Close((BPTR)Iff->iff_Stream);
  198.       }
  199.       FreeIFF(Iff);
  200.    }
  201. }
  202.  
  203. void DoSaveAs()
  204. {
  205.    if (!GetSaveName()) return;
  206.    DoSave();
  207. }
  208.  
  209. static BOOL GetSaveName()
  210. {
  211.    APTR fr;
  212.    BPTR File;
  213.    LONG Response;
  214.  
  215.    fr=MUI_AllocAslRequestTags(ASL_FileRequest,
  216.                               ASL_Hail,(ULONG)"Select Save File",
  217.                               ASL_File,(ULONG)SaveName,
  218.                               ASL_FuncFlags,FILF_SAVE,
  219.                               TAG_END);
  220.    if (MUI_AslRequest(fr,NULL)) {
  221.       strcpy(SaveName,((struct FileRequester *)fr)->rf_Dir);
  222.       AddPart(SaveName,((struct FileRequester *)fr)->rf_File,sizeof(SaveName));
  223.       MUI_FreeAslRequest(fr);
  224.       File=Open(SaveName,MODE_OLDFILE);
  225.       if (File) {
  226.          Close(File);
  227.          Response=MUI_Request(App,NULL,0,NULL,"Yes|*No","Overwrite File?");
  228.          if (Response==0)
  229.             return(FALSE);
  230.       }
  231.       return(TRUE);
  232.    }
  233.    MUI_FreeAslRequest(fr);
  234.    return(FALSE);
  235. }
  236.  
  237.  
  238. void LoadKeys()
  239. {
  240.    LONG  rlen;
  241.    WORD  KeyNum;
  242.    UBYTE LocalKey[MAXKEYLEN];
  243.  
  244.    FOREVER {
  245.       rlen=ReadChunkBytes(Iff,&KeyNum,sizeof(KeyNum));
  246.       if (rlen<=0) break;
  247.       ReadChunkBytes(Iff,LocalKey,MAXKEYLEN);
  248.       AddKeyInPos(KeyNum,LocalKey);
  249.    }
  250. }
  251.  
  252. BOOL LoadAllFloppies(struct List *FList)
  253. {
  254.    FLOPPY *Floppy;
  255.    RECORD *Record;
  256.    STRPTR  String;
  257.    LONG    error;
  258.    short   len;
  259.    BOOL    Parse = FALSE;
  260.  
  261.    FOREVER {
  262.       if (Parse) {
  263.          error=ParseIFF(Iff,IFFPARSE_SCAN);
  264.          if (error==IFFERR_EOC) continue;
  265.          if (error) break;
  266.       } else
  267.          Parse=TRUE;
  268.       if (ChunkIs(ID_FLOPPY,ID_FORM)) {
  269.          Floppy=AllocMem(sizeof(FLOPPY),MEMF_CLEAR);
  270.          if (!Floppy) return(FALSE);
  271.          NewList(&Floppy->Records);
  272.          AddTail(FList,(struct Node *)Floppy);
  273.          FOREVER {
  274.             error=ParseIFF(Iff,IFFPARSE_RAWSTEP);
  275.             if (error==IFFERR_EOC) continue;
  276.             if (error) break;
  277.             if (ChunkIs(NULL,ID_RECORD)) {
  278.                Record=AllocMem(sizeof(RECORD),MEMF_CLEAR);
  279.                if (!Record) return(FALSE);
  280.                ReadChunkBytes(Iff,&Record->Flags,sizeof(Record->Flags));
  281.                ReadChunkBytes(Iff,&Record->Size,sizeof(Record->Size));
  282.                ReadChunkBytes(Iff,&Record->Depth,sizeof(Record->Depth));
  283.                ReadChunkBytes(Iff,&Record->Unique,sizeof(Record->Unique));
  284.                ReadChunkBytes(Iff,&Record->Keys,sizeof(Record->Keys));
  285.                ReadChunkBytes(Iff,&Record->Next,sizeof(Record->Next));
  286.                ReadChunkBytes(Iff,&Record->Parent,sizeof(Record->Parent));
  287.                ReadChunkBytes(Iff,&Record->Sub,sizeof(Record->Sub));
  288.                ReadChunkBytes(Iff,&len,sizeof(len));
  289.                if (len) {
  290.                   String=AllocMem(len,MEMF_CLEAR);
  291.                   if (!String) return(FALSE);
  292.                   ReadChunkBytes(Iff,String,len);
  293.                   Record->FName=String;
  294.                }
  295.                ReadChunkBytes(Iff,&len,sizeof(len));
  296.                if (len) {
  297.                   String=AllocMem(len,MEMF_CLEAR);
  298.                   if (!String) return(FALSE);
  299.                   ReadChunkBytes(Iff,String,len);
  300.                   Record->FRem=String;
  301.                }
  302.                if (!Floppy->HeadRecord)
  303.                   Floppy->HeadRecord=Record;
  304.                AddTail((struct List *)&Floppy->Records,(struct Node *)Record);
  305.             } else if (ChunkIs(ID_FLOPPY,ID_FORM)) {
  306.                Record=(RECORD *)Floppy->Records.lh_Head;
  307.                while (((struct Node *)Record)->ln_Succ) {
  308.                   Record->Next=LinkRecord(Floppy,(ULONG)Record->Next);
  309.                   Record->Parent=LinkRecord(Floppy,(ULONG)Record->Parent);
  310.                   Record->Sub=LinkRecord(Floppy,(ULONG)Record->Sub);
  311.                   Record=(RECORD *)(((struct Node *)Record)->ln_Succ);
  312.                }
  313.                Floppy=AllocMem(sizeof(FLOPPY),MEMF_CLEAR);
  314.                if (!Floppy) return(FALSE);
  315.                NewList(&Floppy->Records);
  316.                AddTail(FList,(struct Node *)Floppy);
  317.             }
  318.          }
  319.          Record=(RECORD *)Floppy->Records.lh_Head;
  320.          while (((struct Node *)Record)->ln_Succ) {
  321.             Record->Next=LinkRecord(Floppy,(ULONG)Record->Next);
  322.             Record->Parent=LinkRecord(Floppy,(ULONG)Record->Parent);
  323.             Record->Sub=LinkRecord(Floppy,(ULONG)Record->Sub);
  324.             Record=(RECORD *)(((struct Node *)Record)->ln_Succ);
  325.          }
  326.       }
  327.    }
  328.    return(TRUE);
  329. }
  330.  
  331. static BOOL GetLoadName()
  332. {
  333.    APTR fr;
  334.  
  335.    fr=MUI_AllocAslRequestTags(ASL_FileRequest,
  336.                               ASL_Hail,(ULONG)"Select Load File",
  337.                               ASL_File,(ULONG)LoadName,
  338.                               TAG_END);
  339.    if (MUI_AslRequest(fr,NULL)) {
  340.       strcpy(LoadName,((struct FileRequester *)fr)->rf_Dir);
  341.       AddPart(LoadName,((struct FileRequester *)fr)->rf_File,sizeof(LoadName));
  342.       MUI_FreeAslRequest(fr);
  343.       return(TRUE);
  344.    }
  345.    MUI_FreeAslRequest(fr);
  346.    return(FALSE);
  347. }
  348.  
  349. void DoLoad()
  350. {
  351.    LONG Response;
  352.    LONG error;
  353.  
  354.    if ((DataChanged) && (FloppyList.lh_Head->ln_Succ)) {
  355.       Response=MUI_Request(App,NULL,0,NULL,"Yes|*No","Lose Changes?");
  356.       if (!Response)
  357.          return;
  358.    }
  359.  
  360.    if (!GetLoadName())
  361.       return;
  362.  
  363.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  364.    if (Iff=AllocIFF()) {
  365.       if (Iff->iff_Stream=(ULONG)Open(LoadName,MODE_OLDFILE)) {
  366.          InitIFFasDOS(Iff);
  367.          if (!OpenIFF(Iff,IFFF_READ)) {
  368.             StopChunk(Iff,ID_FBASE1,ID_FORM);
  369.             StopChunk(Iff,ID_FBASE1,ID_KEYS);
  370.             StopChunk(Iff,ID_FLOPPY,ID_FORM);
  371.             StopChunk(Iff,ID_FLOPPY,ID_RECORD);
  372.             if (ParseIFF(Iff,IFFPARSE_SCAN)==0) {
  373.                FOREVER {
  374.                   error=ParseIFF(Iff,IFFPARSE_SCAN);
  375.                   if (error==IFFERR_EOC) continue;
  376.                   if (error) break;
  377.                   if (ChunkIs(NULL,ID_KEYS)) {
  378.                      FreeKeys();
  379.                      LoadKeys();
  380.                   } else if (ChunkIs(ID_FLOPPY,ID_FORM)) {
  381.                      FreeAllFloppies(&FloppyList);
  382.                      if (!LoadAllFloppies(&FloppyList))
  383.                         FreeAllFloppies(&FloppyList);
  384.                      CreateList(LV_Floppies,&FloppyList);
  385.                   }
  386.                }
  387.                strcpy(SaveName,LoadName);
  388.                DataChanged=FALSE;
  389.             } else
  390.                MUI_Request(App,NULL,0,NULL,"OK","Wrong File Format!");
  391.             CloseIFF(Iff);
  392.          }
  393.          Close((BPTR)Iff->iff_Stream);
  394.       }
  395.       FreeIFF(Iff);
  396.    }
  397.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  398. }
  399.  
  400. static RECORD *LinkRecord(FLOPPY *Floppy,ULONG Unique)
  401. {
  402.    RECORD *Record;
  403.  
  404.    if (Unique==0) return(NULL);
  405.    Record=(RECORD *)Floppy->Records.lh_Head;
  406.    while (((struct Node *)Record)->ln_Succ) {
  407.       if (Record->Unique==Unique) return(Record);
  408.       Record=(RECORD *)(((struct Node *)Record)->ln_Succ);
  409.    }
  410.    return(NULL); /* oh oh */
  411. }
  412.  
  413. static BOOL ChunkIs(ULONG Type,ULONG ID)
  414. {
  415.    struct ContextNode *cn;
  416.  
  417.    if (!(cn=CurrentChunk(Iff)))
  418.       return(FALSE);
  419.    if (ID!=cn->cn_ID)
  420.       return(FALSE);
  421.    if ((Type) && (Type!=cn->cn_Type))
  422.       return(FALSE);
  423.    return(TRUE);
  424. }
  425.  
  426. void DoPrintAll()
  427. {
  428.    FILE        *fd;
  429.    struct Node *FNode,*RNode;
  430.    FLOPPY      *Floppy;
  431.    RECORD      *Record;
  432.  
  433.    fd=fopen("PRT:","w");
  434.    if (!fd) return;
  435.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  436.    fprintf(fd,"\n\33[1mContents of Database:\33[22m\n\n");
  437.    FNode=FloppyList.lh_Head;
  438.    while (FNode->ln_Succ) {
  439.       Floppy=(FLOPPY *)FNode;
  440.       RNode=Floppy->Records.lh_Head;
  441.       while (RNode->ln_Succ) {
  442.          Record=(RECORD *)RNode;
  443.          PrintRecord(fd,Record);
  444.          RNode=RNode->ln_Succ;
  445.       }
  446.       fprintf(fd,"\n");
  447.       FNode=FNode->ln_Succ;
  448.    }
  449.    fclose(fd);
  450.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  451. }
  452.  
  453. void DoPrintTitles()
  454. {
  455.    FILE        *fd;
  456.    struct Node *Node;
  457.    RECORD      *Record;
  458.  
  459.    fd=fopen("PRT:","w");
  460.    if (!fd) return;
  461.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  462.    fprintf(fd,"\n\33[1mFloppies in Database:\33[22m\n\n");
  463.    Node=FloppyList.lh_Head;
  464.    while (Node->ln_Succ) {
  465.       Record=((FLOPPY *)Node)->HeadRecord;
  466.       fprintf(fd,"%s:\n",Record->FName);
  467.       Node=Node->ln_Succ;
  468.    }
  469.    fclose(fd);
  470.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  471. }
  472.  
  473. void DoPrintContents()
  474. {
  475.    FILE        *fd;
  476.    struct Node *Node;
  477.    RECORD      *Record;
  478.  
  479.    fd=fopen("PRT:","w");
  480.    if (!fd) return;
  481.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  482.    fprintf(fd,"\n\33[1mContents of Floppy:\33[22m\n\n");
  483.    Node=MainFloppy->Records.lh_Head;
  484.    while (Node->ln_Succ) {
  485.       Record=(RECORD *)Node;
  486.       PrintRecord(fd,Record);
  487.       Node=Node->ln_Succ;
  488.    }
  489.    fclose(fd);
  490.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  491. }
  492.  
  493. void DoPrintMatch()
  494. {
  495.    FILE   *fd;
  496.    RECORD *Record;
  497.    STRPTR  MatchString;
  498.    LONG    MatchKeysFlag,AndKeysFlag;
  499.    STRPTR *Key;
  500.    WORD    Dummy;
  501.    BOOL    FirstKey = TRUE;
  502.    int     i;
  503.  
  504.    fd=fopen("PRT:","w");
  505.    if (!fd) return;
  506.    set(WI_Main,MUIA_Window_Sleep,TRUE);
  507.    get(ST_Match,MUIA_String_Contents,&MatchString);
  508.    fprintf(fd,"\n\33[1mFiles Matching <%s>\33[22m\n",MatchString);
  509.     get(CM_Keys,MUIA_Selected,&MatchKeysFlag);
  510.     get(CM_KeyAnd,MUIA_Selected,&AndKeysFlag);
  511.     if (MatchKeysFlag) {
  512.        if (AndKeysFlag)
  513.           fprintf(fd,"\33[1mWith Flags (AND) : ");
  514.        else
  515.           fprintf(fd,"\33[1mWith Flags : ");
  516.       InitKeyScan();
  517.       while (Key=GetNextKey(&Dummy))
  518.          if (CurKeyMask & (1<<KeyNumber(*Key)))
  519.             if (FirstKey) {
  520.                fprintf(fd,"%s",*Key);
  521.                FirstKey=FALSE;
  522.             } else
  523.                fprintf(fd,",%s",*Key);
  524.       fprintf(fd,"\33[22m\n\n");
  525.    } else
  526.       fprintf(fd,"\n");
  527.    for (i=0; ; i++) {
  528.       DoMethod(LV_Files,MUIM_List_GetEntry,i,&Record);
  529.       if (!Record) break;
  530.       PrintRecordFull(fd,Record);
  531.    }
  532.    fclose(fd);
  533.    set(WI_Main,MUIA_Window_Sleep,FALSE);
  534. }
  535.  
  536. void DoPrintFInfo()
  537. {
  538.    FILE *fd;
  539.    fd=fopen("PRT:","w");
  540.    if (!fd) return;
  541.    PrintRecordFull(fd,MainRecord);
  542.    fclose(fd);
  543. }
  544.  
  545. static void PrintRecord(FILE *fd,RECORD *Record)
  546. {
  547.    static char tx[108],len[16],buf[128];
  548.    static char space[]="                    ";
  549.  
  550.    strncpy(tx,space,Record->Depth);
  551.    tx[Record->Depth]=0;
  552.    if (Record->Flags & RECORD_DIRECTORY) {
  553.       if (Record->Flags & RECORD_ROOT) {
  554.          sprintf(buf,"\33[1m%s:",Record->FName);
  555.          strcpy(len,"[root]\33[22m");
  556.       } else {
  557.          sprintf(buf,"\33[1m%s",Record->FName);
  558.          strcpy(len,"[dir]\33[22m");
  559.       }
  560.    } else {
  561.       sprintf(buf,"%s",Record->FName);
  562.       sprintf(len,"(%ld)",Record->Size);
  563.    }
  564.    strcat(tx,buf);
  565.    fprintf(fd,"%s %s\n",tx,len);
  566. }
  567.  
  568. static void PrintRecordFull(FILE *fd,RECORD *Record)
  569. {
  570.    static char  tx[108];
  571.    STRPTR      *Key;
  572.    WORD         Dummy;
  573.    BOOL         FirstKey = TRUE;
  574.  
  575.    BuildName(Record,tx);
  576.    if (Record->Flags & RECORD_DIRECTORY)
  577.       fprintf(fd,"FILE    %s\n",tx);
  578.    else
  579.       fprintf(fd,"FILE    %s (%ld)\n",tx,Record->Size);
  580.    if (Record->FRem)
  581.       fprintf(fd," REMARK %s\n",Record->FRem);
  582.    fprintf(fd," KEYS   ");
  583.    InitKeyScan();
  584.    while (Key=GetNextKey(&Dummy))
  585.       if (Record->Keys & (1<<KeyNumber(*Key)))
  586.          if (FirstKey) {
  587.             fprintf(fd,"%s",*Key);
  588.             FirstKey=FALSE;
  589.          } else
  590.             fprintf(fd,",%s",*Key);
  591.    fprintf(fd,"\n");
  592. }
  593.